/*************************************************************************
	> File Name: EP21-1.cpp
	> Author: 
	> Mail: 
	> Created Time: 一  8/19 14:13:18 2019
 ************************************************************************/

#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define max_n 1000000

int f[max_n + 5] = {0};

void keep_fac(int n) {
    int x = n;
    int sum = 0;
    for (int i = 1; i * i <= n; i++) {
        if (n % i) continue;
        sum += i + n / i;
    }
    f[x] = sum;
}

int main() {
    for (int i = 1; i < max_n; i++) {
        keep_fac(i);
        f[i] -= i;
    }
    long long sum = 0;
    for (int i = 2; i < max_n; i++) {
        if (f[i] < max_n && f[i] != i && f[f[i]] == i) {
            sum += i;
        } 
    }
    cout << sum << endl;
    return 0;
}
